/**
 * @description  收益分解（归因分析）
 * @author shenhong
 */
import React, { PureComponent } from 'react';
import { connect } from 'dva';
import { SecondHeaderC, TreeChartsC, ThreeHeaderC } from '../../../../comps';
import style from '../index.less';

class DecomposeIncome extends PureComponent {
  constructor() {
    super();
    this.state = {};
  }
  componentDidMount() {
    const { dispatch, args } = this.props;
    dispatch({
      type: 'attributionAnalysisM/getIncome',
      payload: args,
    });
  }
  UNSAFE_componentWillReceiveProps(nextProps) {
    const { dispatch, args } = nextProps;
    if (JSON.stringify(args) !== JSON.stringify(this.props.args)) {
      dispatch({
        type: 'attributionAnalysisM/save',
        psyload: { Income: undefined },
      });
      dispatch({
        type: 'attributionAnalysisM/getIncome',
        payload: args,
      });
    }
  }

  showCharts = () => {
    const {
      attributionAnalysisM: { Income },
    } = this.props;
    const series = Income;
    return (
      <div style={{ height: '340px' }}>
        <TreeChartsC data={series} height={340} isPercent={true} />
      </div>
    );
  };

  render() {
    const {
      attributionAnalysisM: { Income },
    } = this.props;
    return (
      <div style={{ marginTop: '10px' }} className={style.back_charts}>
        <ThreeHeaderC title={`收益分解（对比基准为${Income && Income.length > 0 ? Income[0].bench_id : ''}）`} />
        <div style={{ height: '340px' }} className='echarts2'>
          {this.showCharts()}
        </div>
      </div>
    );
  }
}
export default connect(({ attributionAnalysisM }) => ({
  attributionAnalysisM,
}))(DecomposeIncome);
